// pages/main/main.js
const app = getApp()
// const innerAudioContext = wx.createInnerAudioContext()      //创建音乐播放器      
var interval = null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    setData: {},
    music_cover: '',
    musicName: '',
    musicList: [],
    animatzFoot: '',
    animatzFootBg: '',
    jiaHide: false,
    playIcon: "/image/stop.png",
    isStop: false,
    bgColors: [
      "#3fa8f4",
      "#ff7b5c",
      "#3dc48d",
      "#065784",
      "#ed9ae6",
      "#3B3354"
    ],


    bgColor: "#3fa8f4",
    timer: 30, //定时
    timerNum: 30,
    usertype: false, //是否完善资料
    topimg: ''
  },



  topjxh: function(e) {
    wx.navigateTo({
      url: '/pages/pjxh/pjxh?xhid=' + e.currentTarget.dataset.xhid
    })
  },
  tossxh: function(e) {
    wx.navigateTo({
      url: '/pages/ssxh/ssxh?xhid=' + e.currentTarget.dataset.xhid,
    })
  },
  todsg(){
    wx.navigateTo({
      url: '/pages/dsg/dsg',
    })
  },
  toshg() {
    wx.navigateTo({
      url: '/pages/shg/shg',
    })
  },
  tocalligraphy: function () {
    wx.navigateTo({
      url: '/pages/calligraphy/calligraphy',
    })
  },
  tobigstone: function () {
    wx.navigateTo({
      url: '/pages/bigstone/bigstone',
    })
  },
  toshop: function() {
    wx.navigateTo({
      url: '/pages/shop/shop',
    })
  },

  serve: function() {
    wx.switchTab({
      url: '/pages/serve/serve',
    })
  },
  mine: function() {
    wx.navigateTo({
      url: '/pages/mine/mine',
    })
  },
  topaimai: function() {
    var self = this;

    wx.request({
      url: app.serverUrl + 'About/isaddress',
      method: 'GET',
      data: {
        openid: app.openid
      },
      success: function(res) {
        console.log(res.data);
        if (res.data.flag == 'success') {
          wx.navigateTo({
            url: '/pages/auction/auction',
          })
        } else {
          wx.chooseAddress({
            success: function(res) {
              // console.log(res);
              self.setData({
                address: {
                  name: res.userName,
                  phone: res.telNumber,
                  address: res.cityName + res.countyName + res.detailInfo
                },
              });
              wx.request({
                url: app.serverUrl + 'About/addressadd',
                method: 'GET',
                data: {
                  openid: app.openid,
                  orderaddress: self.data.address.address,
                  username: self.data.address.name,
                  tel: self.data.address.phone,

                },
                success: function(res) {
                  wx.navigateTo({
                    url: '/pages/auction/auction',
                  })
                }
              })
            },
            fail: function(res) {
              wx.showToast({
                title: '请打开访问您地址的权限',
                icon: 'none'
              })
            }
          })
        }
      }
    })

  },
  toinformation: function() {
    wx.navigateTo({
      url: '/pages/information/information',
    })
  },
  tomuseum: function() {
    wx.navigateTo({
      url: '/pages/museum/museum',
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    if (app.openid==''){
      wx.navigateTo({
        url: '/pages/index/index'
      })
    }
    var that = this;
    console.log(that.data.openid);


    app.openid = wx.getStorageSync(app.globalData.OPENID_KEY);
    console.log(app.openid);
    wx.setNavigationBarTitle({
      title: '大易益',
    })
    app.recomendID = decodeURIComponent(options.scene); //获取推荐人的id
    console.log('推荐人ID', app.recomendID)


  },
  // 初始化数据
  initData: function() {
    var self = this;

    wx.request({
      url: app.serverUrl + 'About/musicList',
      // url: app.serverUrl +'About/showhometaglist',
      method: 'GET',
      data: {
        openid: app.openid
      },
      success: function(res) {
        console.log(res)
        self.setData({
          usertype: res.data.data.usertype
        })
        // if (!res.data.data.usertype) {
        //   wx.navigateTo({
        //     url: '/pages/regist/regist',
        //   })
        // }
        self.setData({
          musicList: res.data.data.list,
          topimg: res.data.data.lunbo
        })
        self.playMusic();
        wx.hideLoading();
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  // onShow: function() {
  //   var self = this;
  //   //判断是否需要跳转到登陆页
  //   app.globalData.userInfo = wx.getStorageSync('userinfo');
  //   app.openid = wx.getStorageSync(app.globalData.OPENID_KEY);
  //   if (app.globalData.userInfo == null || app.openid == '') {
  //     wx.navigateTo({
  //       url: '/pages/index/index',
  //     })
  //   } else {
  //     self.initData();
  //   } 
  // },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    var animation = wx.createAnimation({
      duration: 500,
    })
    animation.translateY(0, -60).step()
    this.setData({
      jiaHide: false,
      animatzFoot: animation.export(),
    })
    //
    // console.log(innerAudioContext.src);
    // console.log(this.data.isStop);

    // console.log('息屏操作');
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    return {
      title: '大易益·传统文化大舞台，爱好者的掌中宝！',
      path: '/pages/index/index'
    }
  }
  // if (res.from === 'button') {
  //   // 来自页面内转发按钮
  //   console.log(res.target)
  // }
  //   return {
  //     title: '春风细雨',
  //     path: '/pages/main/main'
  //   }

})